<!DOCTYPE html>
<html>
<head>
    <div th:include="base-libs :: base-libs"/>
    <title>协议模板列表</title>
    <meta name="content-type" content="text/html; charset=UTF-8">

    <style type="text/css">
    </style>

    <script>
        var xymbBtns = [""];
        $(function () {
            initView();
            $(this).getZydmCache({
                callback: initData
            });
        })
        function initData(cacheData) {
            var TB_ZY_XYMBLX = cacheData["TB_ZY_XYMBLX"];
            if(TB_ZY_XYMBLX){
                $.each(TB_ZY_XYMBLX, function(){
                    xymbBtns.push(this["XMMC"]);
                })
            }
            $("body").data("cacheData", cacheData);
            $("#btnQuery").trigger("click");
        }

        function initView() {
            $("#dg").datagrid({
                idField : "XYMBID",
                striped : true,
                fitColumns : true,
                fit : true,
                border : false,
                rownumbers: true,
                singleSelect: true,
                toolbar : "#tb",
                pagination: true,
                loadMsg: "",
                columns : [[
                    {
                        field : "XYMBID",
                        title : "协议模板编号"
                        ,width: 4
                    }
                    ,{
                        field : "XYMBMC",
                        title : "协议模板名称"
                        ,width: 8,
                        formatter: function(value,row,index){
                            if(row.ZT == '1' && row.XYMBLX == '01'){
                                return value + "<span style='color:red;zoom:1.2'>(启用中)</span>";
                            }else{
                                return value;
                            }
                        }

                    }
                    ,{
                        field : "CJRQ",
                        title : "创建日期",
                        width: 4,
                        formatter:function(value){
                            if(!StringUtils.isEmpty(value)){
                                return value.substring(0,10);
                            }
                        }
                    }
                    ,{
                        field : "XYMBLX",
                        title : "协议模板类型"
                        ,width: 2
                        ,formatter : function(value, row, index){
                            var text = value;
                            var TB_ZY_XYMBLX = $("body").data("cacheData")["TB_ZY_XYMBLX"];
                            $.each(TB_ZY_XYMBLX, function(){
                                if(this["XMDM"] == value){
                                    text = this["XMMC"];
                                    return false;
                                }
                            })
                            return text;
                        }
                    }
                    ,{
                        field : "CZ",
                        title : "操作"
                        ,align: "center"
                        ,width: 2
                        ,formatter : function(value, row, index){
                            /*if(row.XYMBID == '59a64a243dabd420503e24f5'){
                                //排除手动添加的家庭签约模板
                                return '<a class="dgBtn" href="javascript:void(0)" title="查看" style="color: #00c297;">查看</a>';
                            }else{
                                var dgBtn = $("#dgBtn").html();
                                return dgBtn.replace(/XYMBID/g, row["XYMBID"]);
                            }*/
                            var dgBtn = $("#dgBtn").html();
                            return dgBtn.replace(/XYMBID/g, row["XYMBID"]);
                        }
                    }
                ]]
            });
            $("#dg").datagrid("fitColumns");
            $("#dg").datagrid("initPageQuery", {
                url: contextRoot+"/xymb/queryPageXymb.service"
                ,getParamsFunc: getParams
            });

            $("body").on("click", ".dgBtn", function(){
                var FWID = $(this).attr("id");
                $("#dg").datagrid("selectRecord", FWID);
                var item = $("#dg").datagrid("getSelected");
                if(item){
                    var XYMBID = item["XYMBID"];
                    var XYMBLX = item["XYMBLX"];
                    var XYMBMC = item["XYMBMC"];
                    toManager(XYMBLX, {XYMBID: XYMBID, XYMBMC: XYMBMC,ZT:item.ZT});
                }
            })
        }
        /**获取分页查询参数*/
        function getParams(){
            var XYMBMC = $("#XYMBMC").val();
            var XYMBLX = $("#XYMBLX").val();
            return {XYMBMC: XYMBMC, XYMBLX: XYMBLX};
        }

        /**查询按钮回调*/
        function btnQueryHandler(){
            $("#dg").datagrid("queryPage");
        }

        /**新增协议*/
        function btnAddHandler(){
            var TB_ZY_XYMBLX = $("body").data("cacheData")["TB_ZY_XYMBLX"];
            /*$.QuickAlert.alertConfirm({
                content: "请选择要新增的协议模板类型"
                ,btn: xymbBtns
                ,area: ["400px"]
                ,btn2: function(){
                    toManager(TB_ZY_XYMBLX[0]["XMDM"]);
                }
                ,btn3: function(){
                    toManager(TB_ZY_XYMBLX[1]["XMDM"]);
                }
                ,btn4: function(){
                    toManager(TB_ZY_XYMBLX[2]["XMDM"]);
                }
                ,success: function(layero){
                    $(layero).find(".layui-layer-btn0").hide();
                }
            })*/
            xymbBtns = ["","家庭签约协议","医联体协议"]
            $.QuickAlert.alertConfirm({
                content: "请选择要新增的协议模板类型"
                ,btn: xymbBtns
                ,area: ["400px"]
                ,btn2: function(){
                    toManager(TB_ZY_XYMBLX[0]["XMDM"]);
                }
                ,btn3: function(){
                    toManager(TB_ZY_XYMBLX[1]["XMDM"]);
                }
                ,success: function(layero){
                    $(layero).find(".layui-layer-btn0").hide();
                }
            })
        }
        /**根据模板类型跳转新增页面*/
        function toManager(XYMBLX, params){
            var url = contextRoot+"xymb/manager.html?XYMBLX="+XYMBLX;
            if(params){
                $.each(params, function(key, value){

                    /*if(key == "XYMBMC"){
                        StoreCache.setCache("XYMBMC",value);
                    }else{
                        url += "&"+key+"="+value;
                    }*/
                    url += "&"+key+"="+ encodeURI(value);
                })
            }
            location = url;
        }
    </script>

</head>

<body class="easyui-layout">
    <div region="north" border="false" style="overflow:hidden;border:0;background:#f9f9f9">
        <div style="width: 100%; margin-left: 30px">
            <h3 style="line-height: 41px; margin: 0px; font-size: 18px;font-weight: bold;text-align:center">协议模板列表</h3>
        </div>
    </div>
    <div region="center" border="false">
        <table id="dg"></table>
        <div id="tb" style="padding:8px 20px;">
            <form id="queryForm">
                <table>
                    <tr>
                        <td class="query-text">协议模板名称</td>
                        <td class="query-content">
                            <input id="XYMBMC" name="XYMBMC" class="query-input" style="width: 200px;">
                        </td>
                        <td class="query-text">协议类型</td>
                        <td class="query-content">
                            <select id="XYMBLX" cacheTable="TB_ZY_XYMBLX"></select>
                        </td>
                        <td>
                            <button id="btnQuery" class="btn btn-default" type="button" onclick="btnQueryHandler()">查询</button>
                            <button id="btnAdd" class="btn btn-default" type="button" onclick="btnAddHandler()">新增</button>
                        </td>
                    </tr>
                </table>
            </form>
        </div>
    </div>
</body>
<script type="text/html" id="dgBtn">
    <a class="dgBtn" id=XYMBID href="javascript:void(0)" title="修改" style="color: #00c297;">修改</a>
</script>
</html>
